package com.ruoyi.charge.service.impl;

import com.ruoyi.charge.domain.ChargeOrder;
import com.ruoyi.charge.mapper.SelectMapper;
import com.ruoyi.charge.service.SelectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SelectServiceImpl implements SelectService {
    @Autowired
    private SelectMapper selectMapper;

    @Override
    public List<ChargeOrder> getChargeOrderList(String registerNumber, String patientName) {
        List<ChargeOrder> chargeOrderList = null;
        System.out.println("registerNumber = " + registerNumber + ", patientName = " + patientName);
        if (registerNumber == "") {
            Long patientId = selectMapper.getIdByPatientName(patientName);
            chargeOrderList = selectMapper.getChargeOrderList(patientId);//订单集合
        } else {
            Long patientId = selectMapper.getIdByRegisterNumber(registerNumber);
            chargeOrderList = selectMapper.getChargeOrderList(patientId);//订单集合
        }
        return chargeOrderList;
    }

    @Override
    public String getRegisterNumber(String registerNumber, String patientName) {
        String code = null;
        if (registerNumber == "") {
            Long patientId = selectMapper.getIdByPatientName(patientName);
            code = selectMapper.getRegisterNumberByPatientId(patientId);
        } else {
            Long patientId = selectMapper.getIdByRegisterNumber(registerNumber);
            code = selectMapper.getRegisterNumberByPatientId(patientId);
        }
        return code;
    }

    @Override
    public int updateOrder(String orderNumber) {
        return selectMapper.updateOrder(orderNumber);
    }
}
